package com.android.ailaoshan.tools;

import android.app.Activity;
import android.app.Application;
import android.content.Context;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class BaseApplication extends Application {
    private static BaseApplication baseApplication;
    private List<Activity> activityList;

    private Context bContext;

    private String imageFile;
    private String voiceFile;

    @Override
    public void onCreate() {
        super.onCreate();

        baseApplication = BaseApplication.this;
        activityList = new ArrayList<>();

        LitePal.initialize(this);

        bContext = getApplicationContext();
    }

    /**
     * 静态方法，返回baseApplication实例
     */
    public static BaseApplication getInstance() {
        return baseApplication;
    }

    /**
     * 添加activity
     */
    public void addActivity(Activity activity) {
        if (!activityList.contains(activity)) {
            activityList.add(activity);
        }
    }

    /**
     * 销毁单个activity
     */
    public void removeActivity(Activity activity) {
        if (activityList.contains(activity)) {
            activityList.remove(activity);
            activity.finish();
        }
    }

    /**
     * 销毁所有activity
     */
    public void removeAllActivity() {
        for (Activity activity : activityList) {
            activity.finish();
        }
    }

    public String getImageFile() {
        return imageFile;
    }

    public void setImageFile(String imageFile) {
        this.imageFile = imageFile;
    }

    public String getVoiceFile() {
        return voiceFile;
    }

    public void setVoiceFile(String voiceFile) {
        this.voiceFile = voiceFile;
    }

    public Context getbContext() {
        return bContext;
    }
}
